puts "starting script "+__FILE__+" in work directory "+Dir.pwd

def conditional_push( array, value )
	if array.any? { |path| path == value rescue false }
		return 
	else
		$:.push(value)
	end
end

# OS search-directories are not included under sketchup, so include it explicit
if RUBY_PLATFORM =~ /darwin/
  
  # location of cripts must be hardcoded, i have no solution to this problem
  $project_home = "/Users/radek/vm_share/sketchup/mobile_home_0.0"

  conditional_push( $:, "/Library/Ruby/Site/1.8")
  conditional_push( $:, "/Library/Ruby/Site/1.8/powerpc-darwin9.0")
  conditional_push( $:, "/Library/Ruby/Site/1.8/universal-darwin9.0")
  conditional_push( $:, "/Library/Ruby/Site")
  conditional_push( $:, "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8")
  conditional_push( $:, "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/powerpc-darwin9.0")
  conditional_push( $:, "/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0")
  
else
  raise Exception, "Platform \""+RUBY_PLATFORM+"\" not supported yet"
end

require "pathname"

def extend_load_path(path)
  puts "extending load path by "+path
  path_candidate = Pathname.new(path).realpath
  conditional_push( $:, path_candidate )
end

############################################
# please select subproject beeng loaded
# subproject name is the name of subdirectory beeing loaded
# subdirectory must provide function "build_home" building test-home

# first test - parametrized beams construction
#subproject = "beams"

# second test - joist based cells combined together
#subproject = "joist1"

# first objective joist based project
#subproject = "joist_objectiv"

# second objective joist based project
subproject = "joist_cells"

puts "Using subproject "+subproject

for dir in [ "src", "src"+File::Separator+subproject ]
  dir_candidate = $project_home + File::Separator + dir
  extend_load_path( dir_candidate );
  files = Dir.glob( dir_candidate+File::Separator+"*.rb" )
  if files.length > 0 
    files.each { |file| puts "reloading file #{file}"; load file; }
  else
    puts "not ruby files found in "+dir_candidate
  end
end

init
